import { createStore } from "vuex";
import axios from "axios";

const store = createStore({
  state() {
    return {
      data: [],
      list: [],
      num: 0,
    }
  },
  mutations: {
    updata(state, payload) {
      // console.log(payload)
      state.list = payload.data;
      state.data = payload.data[0].foods;
      // console.log(state.list)
    },
    chengS(state, payload) {
      console.log(state.data[payload.index]);
      state.num=state.num+1;
      console.log(state.num);
      // state.data

    }

  },
  actions: {
    getData({ commit }) {
      axios.get("http://localhost:9999/home").then((res) => {
        // console.log(res)
        commit("updata", {
          data: res.data.data[0].goods,
        })
      })
    }
  }
})
export default store;